﻿using System;
using System.Collections.Generic;
using System.Text;
using A2Z.BusinessObjects;
using DataLayer.ObjectMapping;
using KYO.DAL;
using ObjectPersistence;
using BusinessLayerHelper;




namespace A2Z.BusinessService
{
    public class ProjectService
    {
        private ProjectImageAssembler projectImageService = new ProjectImageAssembler();
        public PersistentList<ProjectImage> GetProjectImageList()
        {
            List<ProjectImage> listProjectImage = new List<ProjectImage>();

            PersistentList<ProjectImage> list = projectImageService.ReadCollectionAll();
            return list;
            
            //foreach (ProjectImage p in list)
            //{
                
             
            //    listProjectImage.Add(p);
            //}
          

            //return listProjectImage;
        }
        public List<ProjectImage> GetRandomImage(int number)
        {
            List<ProjectImage> listProjectImage = new List<ProjectImage>();

            PersistentList<ProjectImage> list = projectImageService.ReadCollectionAll();
            
            Random random = new Random();
            int max= list.Count;

            for (int i = 0; i < number; i++)
            {
              

                listProjectImage.Add(list[random.Next(max)]);
               
            }

            return listProjectImage;
        }
        public ProjectImage GetProjectImageById(int id)
        {
            return projectImageService.ReadSingleByKey(id);
            
        }

        public void InsertProjectImage(ProjectImage projectImage)
        {
            projectImage.IsNew = true;
            projectImageService.MakePersistent(projectImage, true);

            


        }
        public void UpdateProjectImage(ProjectImage projectImage)
        {
            
            projectImage.IsNew = false;
            projectImageService.MakePersistent(projectImage, false);
 
        }

        public void CreateProjectImage(ProjectImage projectImage)
        {
            projectImageService.MakePersistent(projectImage, false);
        }


    }
}
